
/********************************************************************

    My simple calculator.

    In this file one function 'calculator_calculation'.
    This function started moved My simple calculator.

********************************************************************/

//-------------------------------------------

#include "std_lib_facilities.h"

//-------------------------------------------

#include "header.h"

//-------------------------------------------

using namespace std;

//-------------------------------------------

// The function of the calculator and custom error handling
void calculator_calculation()
{
    Calculator calc;
    calc.welcome();
    while(cin)
    try{
        calc.get();
        calc.out();
        //cout << "\n= " << calc.result << "\n";
    }
    catch( errornooperands ){
        calc.cleardate();
        cerr << "\nError! No operands!\n\n";
    }
    catch( errornooperators ){
        calc.cleardate();
        cerr << "\nError! No operators!\n\n";
    }
    catch( errortwooperatorsinarow ){
        calc.cleardate();
        cerr << "\nError! Two operators in a row!\n\n";
    }
    catch( erroremptybraces ){
        calc.cleardate();
        cerr << "\nError! Empty braces!\n\n";
    }
    catch( errorbracecorrect ){
        calc.cleardate();
        cerr << "\nError! Incorrect use of braces!\n\n";
    }
    catch( errorseparatorcorrect ){
        calc.cleardate();
        cerr << "\nError! Incorrect use of separator ','!\n\n";
    }
    catch( errorfactorial ){
        calc.cleardate();
        cerr << "\nError! Incorrect use of factorial!\n\n";
    }
    catch( divisionbyzero ){
        calc.cleardate();
        cerr << "\nError! Division by zero! To zero cannot be split!\n\n";
    }
    catch( errorequalscorrect ){
        calc.cleardate();
        cerr << "\nError! Incorrect use of equals!\n\n";
    }
    catch( errorsqrtcorrect ){
        calc.cleardate();
        cerr << "\nError! Incorrect use of function 'sqrt'!\n\n";
    }
    catch( errorpowcorrect ){
        calc.cleardate();
        cerr << "\nError! Incorrect use of function 'pow'!\n\n";
    }
    catch( errordefault ){
        calc.cleardate();
        cerr << "\nError! Enter not correct numbers or operators!\n\n";
    }
    //keep_window_open();
}
